package com.springboot.dao;

import com.springboot.domain.Test;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface TestRepository extends JpaRepository<Test,Integer> {

    List<Test> findByName(String name);

    List<Test> findById(int id);

    List<Test> findByNameAndIdOrderByCreateTimeAsc(String name,int id);

    @Query("from Test where name = ?1 and sex = ?2")
    List<Test> queryByNameHQL(String name,String sex);

    @Query(value = "select * from ssm_test where name = ?1 and sex = ?2",nativeQuery = true)
    List<Test> queryByNameSQL(String name,String sex);

    @Query(value =  "update Test set name = ?1 where id = ?2")
    @Modifying //说明需要执行一个更新操作
    @Transactional
    int updateNameByIdHQL(String name,int id);
}
